replace prod_wheat_value=0 if prod_wheat_value == .
replace prod_cotton_value=0 if prod_cotton_value == .
replace prod_sugar_value=0 if prod_sugar_value == .
replace prod_rice_value=0 if prod_rice_value == .
replace prod_maize_value=0 if prod_maize_value == .
replace prod_pulses_value=0 if prod_pulses_value == .
replace prod_fruits_value=0 if prod_fruits_value == .
replace prod_vegit_value=0 if prod_vegit_value == .
replace prod_fodder_value=0 if prod_fodder_value == .
replace prod_other_value=0 if prod_other_value == .


//replace prod_wheat_value=. if prod_wheat_value == 0
//replace prod_cotton_value=. if prod_cotton_value == 0
//replace prod_sugar_value=. if prod_sugar_value == 0
//replace prod_rice_value=. if prod_rice_value == 0
//replace prod_maize_value=. if prod_maize_value == 0
//replace prod_pulses_value=. if prod_pulses_value == 0
//replace prod_fruits_value=. if prod_fruits_value == 0
//replace prod_vegit_value=. if prod_vegit_value == 0
//replace prod_fodder_value=. if prod_fodder_value == 0
//replace prod_other_value=. if prod_other_value == 0

gen wheat_prod = prod_wheat_value if prod_wheat_value >= prod_cotton_value & prod_wheat_value>= prod_sugar_value & prod_wheat_value>= prod_rice_value & prod_wheat_value >= prod_maize_value & prod_wheat_value>= prod_pulses_value & prod_wheat_value>= prod_fruits_value & prod_wheat_value>= prod_vegit_value & prod_wheat_value>= prod_fodder_value & prod_wheat_value>= prod_other_value
gen cotton_prod= prod_cotton_value if prod_cotton_value>= prod_wheat_value & prod_cotton_value>= prod_sugar_value & prod_cotton_value>= prod_rice_value & prod_cotton_value >= prod_maize_value & prod_cotton_value>= prod_pulses_value & prod_cotton_value>= prod_fruits_value & prod_cotton_value>= prod_vegit_value & prod_cotton_value>= prod_fodder_value & prod_cotton_value>= prod_other_value
gen sugar_prod = prod_sugar_value if prod_sugar_value >= prod_cotton_value & prod_sugar_value>= prod_wheat_value & prod_sugar_value>= prod_rice_value & prod_sugar_value >= prod_maize_value & prod_sugar_value>= prod_pulses_value & prod_sugar_value>= prod_fruits_value & prod_sugar_value>= prod_vegit_value & prod_sugar_value>= prod_fodder_value & prod_sugar_value>= prod_other_value
gen rice_prod = prod_rice_value if prod_rice_value >= prod_cotton_value & prod_rice_value>= prod_wheat_value & prod_rice_value>= prod_sugar_value & prod_rice_value >= prod_maize_value & prod_rice_value>= prod_pulses_value & prod_rice_value>= prod_fruits_value & prod_rice_value>= prod_vegit_value & prod_rice_value>= prod_fodder_value & prod_rice_value>= prod_other_value
gen maize_prod = prod_maize_value if prod_maize_value >= prod_cotton_value & prod_maize_value>= prod_wheat_value & prod_maize_value>= prod_sugar_value & prod_maize_value >= prod_rice_value & prod_maize_value>= prod_pulses_value & prod_maize_value>= prod_fruits_value & prod_maize_value>= prod_vegit_value & prod_maize_value>= prod_fodder_value & prod_maize_value>= prod_other_value
gen pulses_prod = prod_pulses_value if prod_pulses_value >= prod_cotton_value & prod_pulses_value>= prod_wheat_value & prod_pulses_value>= prod_sugar_value & prod_pulses_value >= prod_rice_value & prod_pulses_value>= prod_maize_value & prod_pulses_value>= prod_fruits_value & prod_pulses_value>= prod_vegit_value & prod_pulses_value>= prod_fodder_value & prod_pulses_value>= prod_other_value
gen fruits_prod = prod_fruits_value if prod_fruits_value >= prod_cotton_value & prod_fruits_value>= prod_wheat_value & prod_fruits_value>= prod_sugar_value & prod_fruits_value >= prod_rice_value & prod_fruits_value>= prod_maize_value & prod_fruits_value>= prod_pulses_value & prod_fruits_value>= prod_vegit_value & prod_fruits_value>= prod_fodder_value & prod_fruits_value>= prod_other_value
gen vegit_prod = prod_vegit_value if prod_vegit_value >= prod_cotton_value & prod_vegit_value>= prod_wheat_value & prod_vegit_value>= prod_sugar_value & prod_vegit_value >= prod_rice_value & prod_vegit_value>= prod_maize_value & prod_vegit_value>= prod_pulses_value & prod_vegit_value>= prod_fruits_value & prod_vegit_value>= prod_fodder_value & prod_vegit_value>= prod_other_value
gen fodder_prod = prod_fodder_value if prod_fodder_value >= prod_cotton_value & prod_fodder_value>= prod_wheat_value & prod_fodder_value>= prod_sugar_value & prod_fodder_value >= prod_rice_value & prod_fodder_value>= prod_maize_value & prod_fodder_value>= prod_pulses_value & prod_fodder_value>= prod_vegit_value & prod_fodder_value>= prod_fruits_value & prod_fodder_value>= prod_other_value
gen other_prod = prod_other_value if prod_other_value >= prod_cotton_value & prod_other_value>= prod_wheat_value & prod_other_value>= prod_sugar_value & prod_other_value >= prod_rice_value & prod_other_value>= prod_maize_value & prod_other_value>= prod_pulses_value & prod_other_value>= prod_vegit_value & prod_other_value>= prod_fruits_value & prod_other_value>= prod_fodder_value

gen prod_type=.
replace prod_type=1 if wheat_prod>0 & wheat_prod<.
replace prod_type=2 if cotton_prod>0 & cotton_prod<.
replace prod_type=3 if rice_prod>0 & rice_prod<.
replace prod_type=10 if sugar_prod>0 & sugar_prod<.
replace prod_type=4 if maize_prod>0 & maize_prod<.
replace prod_type=5 if pulses_prod>0 & pulses_prod<.
replace prod_type=6 if fruits_prod>0 & fruits_prod<.
replace prod_type=7 if vegit_prod>0 & vegit_prod<.
replace prod_type=8 if fodder_prod>0 & fodder_prod<.
replace prod_type=9 if other_prod>0 & other_prod<.

gen prod_type1=.
replace prod_type1=1 if prod_type==1 
replace prod_type1=2 if prod_type==2 | prod_type==3 | prod_type==10
replace prod_type1=3 if prod_type==4 | prod_type==8
replace prod_type1=4 if prod_type==5 | prod_type==7
replace prod_type1=5 if prod_type==6
replace prod_type1=6 if prod_type==9 


gen prod_type2=.
replace prod_type2=1 if prod_type==1 | prod_type==3
replace prod_type2=2 if prod_type==2 | prod_type==10
replace prod_type2=3 if prod_type==4 | prod_type==8
replace prod_type2=4 if prod_type==5 | prod_type==7
replace prod_type2=5 if prod_type==6
replace prod_type2=6 if prod_type==9 

egen yieldpa_prod_type2= mean (yieldpa), by (prod_type2)
egen yieldpa_prod_type2_size= mean (yieldpa), by (prod_type2 farm_size_dummy)


gen wheat_yield= wheat_prod/land_culti_total
gen cotton_yield= cotton_prod/land_culti_total
gen sugar_yield= sugar_prod/land_culti_total
gen rice_yield= rice_prod/land_culti_total
gen maize_yield= maize_prod/land_culti_total
gen pulses_yield= pulses_prod/land_culti_total
gen fruits_yield= fruits_prod/land_culti_total
gen vegit_yield= vegit_prod/land_culti_total
gen fodder_yield= fodder_prod/land_culti_total
gen other_yield= other_prod/land_culti_total

//egen wheat_yield_size = mean (wheat_yield), by (farm_size_dummy)
//egen cotton_yield_size = mean (cotton_yield), by (farm_size_dummy)
//egen sugar_yield_size = mean (sugar_yield), by (farm_size_dummy)
//egen rice_yield_size = mean (rice_yield), by (farm_size_dummy)
//egen maize_yield_size = mean (maize_yield), by (farm_size_dummy)
//egen pulses_yield_size = mean (pulses_yield), by (farm_size_dummy)
//egen fruits_yield_size = mean (fruits_yield), by (farm_size_dummy)
//egen vegit_yield_size = mean (vegit_yield), by (farm_size_dummy)
//egen fodder_yield_size = mean (fodder_yield), by (farm_size_dummy)
//egen other_yield_size = mean (other_yield), by (farm_size_dummy)


egen wheat_yield_size = mean (wheat_yield), by (farm_size_dummy province)
egen cotton_yield_size = mean (cotton_yield), by (farm_size_dummy province)
egen sugar_yield_size = mean (sugar_yield), by (farm_size_dummy province)
egen rice_yield_size = mean (rice_yield), by (farm_size_dummy province)
egen maize_yield_size = mean (maize_yield), by (farm_size_dummy province)
egen pulses_yield_size = mean (pulses_yield), by (farm_size_dummy province)
egen fruits_yield_size = mean (fruits_yield), by (farm_size_dummy province)
egen vegit_yield_size = mean (vegit_yield), by (farm_size_dummy province)
egen fodder_yield_size = mean (fodder_yield), by (farm_size_dummy province)
egen other_yield_size = mean (other_yield), by (farm_size_dummy province)
egen total_yield_size = mean (yieldpa), by (farm_size_dummy province)

collapse (mean) wheat_yield_size sugar_yield_size rice_yield_size maize_yield_size pulses_yield_size fruits_yield_size vegit_yield_size fodder_yield_size other_yield_size total_yield_size, by (farm_size_dummy province)
